//JS容错代码，不提示错误。
window.onerror=function (){return true;}
var tst = -1;
function radioChange(sorttype){
	if(tst==sorttype){return;}else{tst = sorttype;}
	if(sorttype==0){
	 	$(".px a").attr("disabled","disabled");
	 	$(".px a").attr("style","display:none;");
	 	$(".px").each(function (){
	 		var text = $(this).html();
	 		$(this).html(text+"&nbsp;\u6392\u5e8f");		
	 		$(this).attr("style","color:gray;");	
	 	});
		var id = 'sortDiv';
		hidePopWin(id);
	 }else{
	 	$(".px a").removeAttr("disabled");
	 	$(".px a").attr("style","display:inline;");
	 	$(".px").each(function (){
	 		var text = $(this).html();		
	 		$(this).removeAttr("style");	
	 		$(this).html(text.substring(0,text.length-2));		
	 	});
	 }
}
function putSortNumToInput(val){
	$("#sortNum").val(val);
}
$(document).ready(function (){
	$("#selectSortNum").click(function (){
		putSortNumToInput($(this).val());
	}).change(function (){
		putSortNumToInput($(this).val());
	});
	
	
	radioChange($("input[name='RadioGroup1']:checked").val());
	$("input[name='RadioGroup1']").click(function (){
		 var roomid = $("#jsroomid").val();
		 var sorttype=$(this).val();
		 if(sorttype==0){
		 	radioChange(0);
		 }else{
		 	radioChange(1);
		 }
		 $.ajax({
			type: "POST",		
			url: "/room!modRoomType.jspa", 
			dataType : "json",
			data:{"roomid":roomid,"sorttype":sorttype},
       		complete : function (data, textStatus){
       			
			}
		});	
	});
	$(".close").click(function (){
		hidePopWin($(this).parent().parent().parent().attr("id"));
   		return false;
	});
});
function updown(obj){
	var reg1 = /^\d+$/;
	var val = $(obj).val();
	if(val.match(reg1) == null){
		 $(obj).val(val.substring(0,val.length-1));
	}
	if(val.length>4){
		 $(obj).val(val.substring(0,4));
	}
}
function initSortDiv(starId){
	$("#sortNum").unbind("keyup");
	$("#sortNum").unbind("keydown");
	$("#subSort").unbind("click");
	$("#cancelSort").unbind("click");
	$("#cancelSort").click(function (){
		var id = 'sortDiv';
		hidePopWin(id);
   		return false;
	});
	$("#sortNum").keyup(function (){
		updown(this);
	})
	.keydown(function (){
		updown(this);
	});
	$("#subSort").click(function (){
		
		var val = $("#sortNum").val();
		if(val==""){
			var id = 'sortDiv';
			hidePopWin(id);
		}
		$.ajax({
			type: "POST",		
			url: "/room!modStarSort.jspa", 
			dataType : "json",
			data:{"starId":starId,"sort":val,"roomid":$("#jsroomid").val()},
       		complete : function (data, textStatus){
       			if (eval("(" + data.responseText + ")").result == 0){
       				window.location.reload();
       			}else{
       				alert("\u53ea\u6709\u5ba4\u4e3b\u624d\u80fd\u8fdb\u884c\u6392\u5e8f\u3002");
       			}
			}
		});	
   		return false;
	});
}
